<?php

/**
 * JPhpMailer class file.
 *
 * @version alpha 2 (2010-6-3 16:42)
 * @author jerry2801 <jerry2801@gmail.com>
 * @required PHPMailer v5.1
 *
 * A typical usage of JPhpMailer is as follows:
 * <pre>
 * Yii::import('ext.phpmailer.JPhpMailer');
 * $mail=new JPhpMailer;
 * $mail->IsSMTP();
 * $mail->Host='smpt.163.com';
 * $mail->SMTPAuth=true;
 * $mail->Username='yourname@yourdomain';
 * $mail->Password='yourpassword';
 * $mail->SetFrom('name@yourdomain.com','First Last');
 * $mail->Subject='PHPMailer Test Subject via smtp, basic with authentication';
 * $mail->AltBody='To view the message, please use an HTML compatible email viewer!';
 * $mail->MsgHTML('<h1>JUST A TEST!</h1>');
 * $mail->AddAddress('whoto@otherdomain.com','John Doe');
 * $mail->Send();
 * </pre>
 */

require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'class.phpmailer.php';

class JPhpMailer extends PHPMailer
{
    public function sendBy139($email,$subject,$message,$username=null, $ccEmail = null, $isNeedBCC = true, $cate = '') {

        // 换新的邮件发送方式
        $this->IsSMTP();
        $this->Host = 'smtp.139.com';
        $this->SMTPAuth = true;
        $this->Username = 'chanzonghuang@139.com';
        $this->Password = 'phalapi2x';
        $this->CharSet = 'utf-8';
        $this->SetFrom('chanzonghuang@139.com', 'PhalApi 开源社区');

        $this->Subject = $subject;
        $this->MsgHTML($message);
        $this->AddAddress($email, !empty($username) ? $username : $email);

        // 抄送
        if (!empty($ccEmail)) {
            $this->addCC($ccEmail);
        }
        // 密送
        if ($isNeedBCC) {
            //$this->AddBCC('helper@okayapi.com', '自己');
        }

        $this->Timeout = 10;
        $this->SMTPSecure = 'ssl';
        $this->Port = 465;

        $rs = $this->Send();

        return $rs;
    }

}
